﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.WmsManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.WmsManagement.InboundVMs
{
    public partial class InboundListVM : BasePagedListVM<Inbound_View, InboundSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Inbound_View>> InitGridHeader()
        {
            return new List<GridColumn<Inbound_View>>{
                
                this.MakeGridHeader(x => x.Inbound_SheetId).SetTitle(@Localizer["Page.入库单号"].Value),
                this.MakeGridHeader(x => x.Inbound_SheetNo).SetTitle(@Localizer["Page.入库单号"].Value),
                this.MakeGridHeader(x => x.Inbound_InMode).SetTitle(@Localizer["Page.入库方式"].Value),
                this.MakeGridHeader(x => x.Inbound_Material).SetTitle(@Localizer["Page.物料"].Value),
                this.MakeGridHeader(x => x.Inbound_InQty).SetTitle(@Localizer["Page.入库数量"].Value),
                this.MakeGridHeader(x => x.Inbound_InBatch).SetTitle(@Localizer["Page.入库批次"].Value),
                this.MakeGridHeader(x => x.Inbound_InboundDate).SetTitle(@Localizer["Page.入库时间"].Value),
                this.MakeGridHeader(x => x.Inbound_InOperator).SetTitle(@Localizer["Page.入库操作"].Value),
                this.MakeGridHeader(x => x.Inbound_SupplierName).SetTitle(@Localizer["Page.供应商"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Inbound_View> GetSearchQuery()
        {
            var query = DC.Set<Inbound>()
                
                .CheckEqual(Searcher.SheetId, x=>x.SheetId)
                .CheckContain(Searcher.SheetNo, x=>x.SheetNo)
                .CheckEqual(Searcher.InMode, x=>x.InMode)
                .CheckEqual(Searcher.MaterialId, x=>x.MaterialId)
                .CheckEqual(Searcher.InQty, x=>x.InQty)
                .CheckContain(Searcher.InBatch, x=>x.InBatch)
                .CheckBetween(Searcher.InboundDate?.GetStartTime(), Searcher.InboundDate?.GetEndTime(), x => x.InboundDate, includeMax: false)
                .CheckContain(Searcher.InOperator, x=>x.InOperator)
                .CheckEqual(Searcher.SupplierId, x=>x.SupplierId)
                .CheckContain(Searcher.SupplierName, x=>x.SupplierName)
                .Select(x => new Inbound_View
                {
				    ID = x.ID,
                    
                    Inbound_SheetId = x.SheetId,
                    Inbound_SheetNo = x.SheetNo,
                    Inbound_InMode = x.InMode,
                    Inbound_Material = x.Material.TenantCode,
                    Inbound_InQty = x.InQty,
                    Inbound_InBatch = x.InBatch,
                    Inbound_InboundDate = x.InboundDate,
                    Inbound_InOperator = x.InOperator,
                    Inbound_SupplierName = x.SupplierName,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Inbound_View: Inbound
    {
        
        public long? Inbound_SheetId { get; set; }
        public string Inbound_SheetNo { get; set; }
        public InOutEnum? Inbound_InMode { get; set; }
        public string Inbound_Material { get; set; }
        public decimal? Inbound_InQty { get; set; }
        public string Inbound_InBatch { get; set; }
        public DateTime? Inbound_InboundDate { get; set; }
        public string Inbound_InOperator { get; set; }
        public string Inbound_SupplierName { get; set; }

    }

}